package com.gjt.zyglxt.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import com.gjt.zyglxt.dao.IRoleDao;
import com.gjt.zyglxt.model.Role;

import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/role")
public class RoleController {

    @Resource
    private IRoleDao roleDao;
    @ApiOperation(value = "角色查询",notes = "角色查询")
    @GetMapping("/findAll")
    public Map<String,Object> findAll(){
        List<Role> list = roleDao.findAll();
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("code", 0);
        map.put("msg", "查询成功");
        map.put("count", list.size());
        map.put("data", list);
        return map;
    }

    @ApiOperation(value = "添加/修改角色",notes = "添加/修改角色")
    @PostMapping("/addOrEdit")
    public Role addOrEdit(Role r){
        return roleDao.save(r);
    }

    @ApiOperation(value = "删除角色",notes = "删除角色")
    @DeleteMapping("/del")
    public void del(@PathVariable Integer id){
        roleDao.deleteById(id);
    }
}